package com.littlebee.storychild.ui.superFragment;

import android.app.Dialog;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v4.app.Fragment;



/**
 * Fragment基类，所有Fragment都要继承此类
 */
public class BaseFragment extends Fragment {

    private static final String TAG = BaseFragment.class.getSimpleName();

    public OnChangePositionListener listener;

    Dialog progressDialog = null;

    public interface OnChangePositionListener {
        public void onChange(int position);
    }

    public void setChangePositionListener(OnChangePositionListener listener) {
        this.listener = listener;
    }


    public int getVersion() {
        int versionCode = 0;
        PackageManager manager = getActivity().getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0);
            versionCode = info.versionCode; //版本名
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    /**
     * 显示进度对话框
     */
    public void showProcessDialog() {
        showProcessDialog("正在提交数据");
    }

    /**
     * 显示进度对话框
     *
     * @param msg
     */
    public void showProcessDialog(String msg) {
        if (progressDialog == null) {

        } else {
            progressDialog.show();
        }
    }

    /**
     * 关闭进度对话框
     */
    public void closeProcessDialog() {
        if (progressDialog != null) {
            progressDialog.dismiss();
            progressDialog = null;
        }
    }
}
